<!-- 首页 -->
<template>
    <div>
      <iframe id="iframe" :src="url" style="width: 100%; height: calc(100vh - 13vh)"></iframe>
    </div>
  </template>
  
  <script setup name="home">
    import { onMounted, ref } from "vue";
  
    let url = ref('')
    let myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/json");
    myHeaders.append("Accept", "*/*");
    myHeaders.append("Host", "10.6.100.106:8200");
    myHeaders.append("Connection", "keep-alive");
  
    let raw = `{"userName":"${JSON.parse(localStorage.getItem("userMessage")).user_account}","password":"sywYALdFM@yf"}`;
  
    // 页面加载时
    onMounted(async () => {
  
      let requestOptions = {
        method: 'POST',
        headers: myHeaders,
        body: raw,
        redirect: 'follow'
      };
      let herf = window.location.href
      let res = await fetch("/forguncy/equipmentplatform/SSO/GetUserToken", requestOptions)
      let str = await res.text()
      let proj_oid = JSON.parse(localStorage.getItem("selectedProject")).proj_oid
      let maxPermission = JSON.parse(localStorage.getItem("userMessage")).maxPermission
      url.value = `https://10.6.100.106:8200/equipmentplatform/${herf.slice(herf.lastIndexOf('/')+1)}?token=${str}&maxPermission=${maxPermission}&proj_oid=${proj_oid}`
    //   let obj = {
    //     project:JSON.parse(localStorage.getItem("project")),
    //     userMessage: JSON.parse(localStorage.getItem("userMessage"))
    //  }

    //  document.getElementById("iframe").onload = () => {
    //   obj.time = 0
    //   document.getElementById("iframe").contentWindow.postMessage(obj, "*")
      
    //   console.log('send')
    //   setTimeout(() => {
    //     obj.time = 2000
    //     document.getElementById("iframe").contentWindow.postMessage(obj, "*")
        
    //     console.log('send_2000')
    //   }, 2000)
    //   setTimeout(() => {
    //     obj.time = 5000
    //     document.getElementById("iframe").contentWindow.postMessage(obj, "*")
        
    //     console.log('send_5000')
    //   }, 5000)
    //  }
     
      
    });
  </script>
  
  <style scoped lang="scss">
    iframe {
      border: none;
      background-color: white;
    }
  </style>